home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_19_1987_Transactor_Publishing.d64 / sorting demo (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  542b  |  23 lines

  1. 10 input"how many names";n
  2. 20 dim a(n),b(n),a$(n),t$(n)
  3. 30 for j=1 to n: print: print"number";j
  4. 40 input"surname";s$
  5. 50 input"first name";f$
  6. 60 t$(j)=s$+", "+f$: rem combine surnames with last names
  7. 70 input"age";a$(j)
  8. 80 a(j)=j: h=j+1
  9. 90 h=h-1: if t$(j)<t$(a(h-1))then a(h)=a(h-1): goto 90: rem sort names
  10. 100 a(h)=j
  11. 110 b(j)=j: h=j+1
  12. 120 h=h-1: if a$(j)<a$(b(h-1))then b(h)=b(h-1): goto 120: rem sort ages
  13. 130 b(h)=j
  14. 140 next j
  15. 150 print: print"sorted alphabetically"
  16. 160 for j=1 to n
  17. 170 print t$(a(j)), a$(a(j))
  18. 180 next j
  19. 190 print:print" sorted by age:"
  20. 200 for j=1 to n
  21. 210 print t$(b(j)), a$(b(j))
  22. 220 next j
  23.